<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>项目管理</title>


    <link type="text/css" href="/TopJUI/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/TopJUI/topjui/themes/default/topjui.green.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/TopJUI/topjui/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="/TopJUI/static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="/TopJUI/topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="/TopJUI/topjui/js/locale/topjui.lang.zh_CN.js"></script>

    <script type="text/javascript" src="/pages/js/moment.min.js"></script>
    <script type="text/javascript" src="/pages/js/layer/layer.js"></script>
    <script type="text/javascript" src="/pages/js/util.js"></script>

    <script type="text/javascript" src="/pages/js/base-loading.js"></script>
    <script type="text/javascript" src="/pages/js/shuoheUtil.js"></script>

    <style type="text/css">
        html, body{ margin:0; height:100%; }
    </style>

</head>
<body class="easyui-layout">

    <div data-options="region:'west',iconCls:'icon-reload',title:'',split:true" style="width:15%;">           
        <table id="tt" style="height:100%;width: 100%;" title="" data-options="
                  idField:'id',
                  treeField:'project_name',
                  method:'get'
                ">
          <thead>
              <tr>
                  <th field="project_name" width="100%">项目</th>
                  <th field="id" width="0px" hidden="true">序列</th>
              </tr>
          </thead>
        </table>        
    </div>

    <div data-options="region:'center',iconCls:'icon-reload',title:'',split:true" style="width:100%;height: 100%">
        <table id="dg" class='easyui-datagrid' style="width:100%;height:100%" title="" data-options="
                  rownumbers:true,
                  singleSelect:true,
                  autoRowHeight:false,
                  pagination:false,
                  fitColumns:false,
                  striped:true,
                  checkOnSelect:true,
                  selectOnCheck:true,
                  collapsible:false,
                  toolbar:'#tb',
                  pageSize:20">
            <thead>
              <tr href="#">
              </tr>
            </thead>
          </table>
          <div id="tb" style="height:35px">            
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-plus',plain:true" onclick="add()" style="margin-left: 30px" disabled>新增</a>
            <a id='btnUpdate' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-pencil',plain:true" onclick="edit()" disabled>修改</a>
<!--             <a id='btnEdit' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-arrow-up',plain:true" onclick="upMove()">上移</a>    
            <a id='btnEdit' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-arrow-down',plain:true" onclick="downMove()">下移</a>    --> 
            <a id='btnEdit' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-hand-pointer-o',plain:true" onclick="view()" >查看</a>                    
            <a id='btnDelete' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-trash',plain:true" onclick="dele()" disabled>删除</a>
            <a id='btnChange' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-retweet',plain:true" onclick="change()" disabled>变更</a>            
            <form id="queryForm" class="search-box">
                  <input class="easyui-combobox" id='project_name' data-options="prompt:'公司名称'">
               <!--    <input class="easyui-textbox" id='equipment_name' data-options="prompt:'公司地址'">
                  <a id='btnQuery' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-search" onclick="functionQuery()" style="margin-left: 0px">搜索</a>          
                  <a id='btnClear' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-refresh" onclick="functionClear()" style="margin-left: 0px">清除</a>                     --> 
              </form>            
          </div>
       </div>
    </div>




  <script type="text/javascript">
    var project = new Object();


    $(function(){
    	loadDg();
    });
    


    function loadDg() {

        $('#tt').treegrid({
            url: '/develop/url/getUrl.do',
            queryParams: {
                'name': 'getProjectListForCombobox'
            },
            onClickRow: function(rowIndex) {
                var rr_row = $('#tt').treegrid('getSelected');  
                project = rr_row;   
                console.info('22222222222222');
                shuoheUtil.layerTopMaskOn();   
                $.ajax({
                    url: '/pm2/plan/getDayListByPlan.do',
                    data: {
                        'project_id': project.id
                    },
                    success: function(data) {
                        console.info(data);                    
                        if(data != null && data !='')
                        {
                            for(var i=0;i<data[1].length;i++)
                            {
                                data[1][i].formatter = function(value,row,index)
                                {
                                    if(value == 1)
                                        return '';
                                    else
                                        return ''
                                }
                                data[1][i].styler = function(value,row,index)
                                {
                                    if(value == 1)
                                        return 'background-color:#00CD66';
                                    else if(value == 'holiday')
                                        return 'background-color:DeepSkyBlue;';
                                    else if(value == 'weeked')
                                        return 'background-color:HotPink;';
                                    else
                                        return 'width:30px';
                                }
                            }
                        }        
                        // data.push(forzenColu);                
                        writeObj(data)
                    }
                });
            },
            onLoadSuccess: function(data) {}
        });

 

 
    }


    function writeObj(data) {
        $('#dg').datagrid({
            url: '/pm2/plan/getDayPlanList.do',
            method: 'get',
            frozenColumns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'project_stage',
                    title: '项目阶段',
                    align: 'left',
                    width:'80'
                }, {
                    field: 'plan_content',
                    title: '任务内容',
                    align: 'left',
                    width:'130',
                    nowrap:true
                }, {
                    field: 'task_level_1',
                    title: '一级分解',
                    align: 'left',
                    width:'130'
                }, {
                    field: 'task_level_2',
                    title: '二级分解',
                    align: 'left',
                    width:'100'
                }, {
                    field: 'task_level_3',
                    title: '三级分解',
                    align: 'left',
                    width:'100'
                }, {
                    field: 'developer',
                    title: '参与人员',
                    align: 'left',
                    width:'100'
                }, {
                    field: 'plan_start_date',
                    title: '起始日期',
                    align: 'left',
                    width: '90'
                }, {
                    field: 'plan_end_date',
                    title: '结束如期',
                    align: 'left',
                    width: '90'
                }, {
                    field: 'plan_manday',
                    title: '人天',
                    align: 'left',
                    width: '40'
                }, {
                    field: 'sort_number',
                    title: '人天',
                    align: 'left',
                    width:'40',
                    hidden:true
                }]
            ],
            columns: data,
            queryParams: {
                'project_id': project.id
            },
            onLoadSuccess: function(data) {
                console.info(data);
                    // var merges = [{
                    //     index: 2,
                    //     rowspan: 2
                    // },{
                    //     index: 5,
                    //     rowspan: 2
                    // },{
                    //     index: 7,
                    //     rowspan: 2
                    // }];
                // var merges = new Array();
                // var project_stage='';
                // var index = 0;
                // var rowspan = 0;
                // for(var i=0;i<data.rows.length;i++)
                // {                    
                //     if(project_stage != data.rows[i])
                //     {
                //         index = i;
                //         project_stage = data.rows[i];
                //     }
                // }

            // for(var i=0; i<merges.length; i++){
            //     $(this).datagrid('mergeCells',{
            //         index: merges[i].index,
            //         field: 'productid',
            //         rowspan: merges[i].rowspan
            //     });
            // }

                mergesCellsDeveloper(data);

                mergesCellsproject_stage(data);
                mergesCellsPlan_content(data);

                mergesCellstask_level_1(data);
                mergesCellstask_level_2(data);
                mergesCellstask_level_3(data);

                shuoheUtil.layerTopMaskOff();
            }
        });
    }
    var mergesCellsproject_stage = function(data)
    {
        var rowspan_ = 0;
        for(var i=0;i<data.rows.length;i++)
        {          
            try
            {
                if(data.rows[i].project_stage == data.rows[i+1].project_stage)
                {
                    rowspan_++;
                }
                else
                {
                    $('#dg').datagrid('mergeCells',{
                        index: i-rowspan_,
                        field: 'project_stage',
                        rowspan: rowspan_+1
                    });
                    rowspan_ = 0
                }
            }
            catch(err)
            {
                $('#dg').datagrid('mergeCells',{
                    index: i-rowspan_,
                    field: 'project_stage',
                    rowspan: rowspan_+1
                });
                rowspan_ = 0
            }
        }
    }

    var mergesCellsDeveloper = function(data)
    {
        var rowspan_ = 0;
        for(var i=0;i<data.rows.length;i++)
        {          
            try
            {
                if(data.rows[i].developer == data.rows[i+1].developer)
                {
                    rowspan_++;
                }
                else
                {
                    $('#dg').datagrid('mergeCells',{
                        index: i-rowspan_,
                        field: 'developer',
                        rowspan: rowspan_+1
                    });
                    rowspan_ = 0
                }
            }
            catch(err)
            {
                $('#dg').datagrid('mergeCells',{
                    index: i-rowspan_,
                    field: 'developer',
                    rowspan: rowspan_+1
                });
                rowspan_ = 0
            }
        }
    }
    var mergesCellsPlan_content = function(data)
    {
        var rowspan_ = 0;
        for(var i=0;i<data.rows.length;i++)
        {          
            try
            {
                if(data.rows[i].plan_content == data.rows[i+1].plan_content)
                {
                    rowspan_++;
                }
                else
                {
                    $('#dg').datagrid('mergeCells',{
                        index: i-rowspan_,
                        field: 'plan_content',
                        rowspan: rowspan_+1
                    });
                    rowspan_ = 0
                }
            }
            catch(err)
            {
                $('#dg').datagrid('mergeCells',{
                    index: i-rowspan_,
                    field: 'plan_content',
                    rowspan: rowspan_+1
                });
                rowspan_ = 0
            }
        }
    }
    var mergesCellstask_level_1 = function(data)
    {
        var rowspan_ = 0;
        for(var i=0;i<data.rows.length;i++)
        {          
            try
            {
                if(data.rows[i].task_level_1 == data.rows[i+1].task_level_1)
                {
                    rowspan_++;
                }
                else
                {
                    $('#dg').datagrid('mergeCells',{
                        index: i-rowspan_,
                        field: 'task_level_1',
                        rowspan: rowspan_+1
                    });
                    rowspan_ = 0
                }
            }
            catch(err)
            {
                $('#dg').datagrid('mergeCells',{
                    index: i-rowspan_,
                    field: 'task_level_1',
                    rowspan: rowspan_+1
                });
                rowspan_ = 0
            }
        }
    }    
    var mergesCellstask_level_2 = function(data)
    {
        var rowspan_ = 0;
        for(var i=0;i<data.rows.length;i++)
        {          
            try
            {
                if(data.rows[i].task_level_2 == data.rows[i+1].task_level_2)
                {
                    rowspan_++;
                }
                else
                {
                    $('#dg').datagrid('mergeCells',{
                        index: i-rowspan_,
                        field: 'task_level_2',
                        rowspan: rowspan_+1
                    });
                    rowspan_ = 0
                }
            }
            catch(err)
            {
                $('#dg').datagrid('mergeCells',{
                    index: i-rowspan_,
                    field: 'task_level_2',
                    rowspan: rowspan_+1
                });
                rowspan_ = 0
            }
        }
    }        
    var mergesCellstask_level_3 = function(data)
    {
        var rowspan_ = 0;
        for(var i=0;i<data.rows.length;i++)
        {          
            try
            {
                if(data.rows[i].task_level_3 == data.rows[i+1].task_level_3)
                {
                    rowspan_++;
                }
                else
                {
                    $('#dg').datagrid('mergeCells',{
                        index: i-rowspan_,
                        field: 'task_level_3',
                        rowspan: rowspan_+1
                    });
                    rowspan_ = 0
                }
            }
            catch(err)
            {
                $('#dg').datagrid('mergeCells',{
                    index: i-rowspan_,
                    field: 'task_level_3',
                    rowspan: rowspan_+1
                });
                rowspan_ = 0
            }
        }
    }       
    // var mergesCells = function(data)
    // {
    //     for(var i=0;i<data.rows.length;i++)
    //     {
    //         var index = i;
    //         var rowspan_ = 0;
    //         for(var x=rowspan_;x<data.rows.length;x++)
    //         {
    //             console.info('1 = '+data.rows[i].project_stage+'  2='+data.rows[x].project_stage);
    //             if(data.rows[i].project_stage == data.rows[x].project_stage)
    //             {
    //                 console.info('..... x='+x+'.......i='+i);
    //                 rowspan_ ++;
                    
    //                 // break;
    //             }
    //             else
    //             {
    //                 console.info('----- x='+x+'------i='+i);
    //                 i =x+1;
    //                 break;
    //             }
    //         }
    //         console.info('index = '+index+'  rowspan_ = '+rowspan_+'  i='+i);
    //         $('#dg').datagrid('mergeCells',{
    //             index: index,
    //             field: 'project_stage',
    //             rowspan: rowspan_+1
    //         });
    //         rowspan_ = 0;
    //     }
    // }

    // var mergesCells = function(data)
    // {
    //     var _last = '';
    //     var index = 0;
    //     var flag = 0;
    //     var start_flag = 0;
    //     for(var i=0;i<data.rows.length;i++)
    //     {       
    //         console.info('111 _last = '+_last+'  index '+index+' flag = '+flag+' start_flag= '+start_flag);

    //         // console.info(data.rows[i]);
    //         if(data.rows[i].task_level_1 != _last)
    //         {
    //             start_flag = i;
    //             _last = data.rows[i].task_level_1;    
    //             console.info('222 _last = '+_last+'  index '+index+' flag = '+flag+' start_flag= '+start_flag);                                           
    //             if(flag > 0)
    //             {                    
    //                 console.info('333 _last = '+_last+'  index '+index+1+' flag = '+flag+' start_flag= '+start_flag);
    //                 $('#dg').datagrid('mergeCells',{
    //                     index: start_flag,
    //                     field: 'task_level_1',
    //                     rowspan: index+1
    //                 });
    //                 index = 0;
    //             }
               
    //             flag ++;
    //         }
    //         else
    //         {
    //             console.info('444 _last = '+_last+'  index '+index+1+' flag = '+flag+' start_flag= '+start_flag);
    //             index ++;
    //         }
    //     }
    // }

    var dealformatter = function(val,row)
    {

    }


	</script>




</body>
</html>
<script type="text/javascript">
    function add() {
        var row = $('#dg').datagrid('getSelected');
        if(row == null)
        {
          layer.open({
              type: 2,
              title: '新增',
              shadeClose: false,
              shade: 0.3,
              maxmin: true, //开启最大化最小化按钮s
              area: ['800px','500px'],
              content: 'form/addPlan.jsp?id='+project.id
          })
        }
        else
        {
            layer.open({
                type: 2,
                title: '新增',
                shadeClose: false,
                shade: 0.3,
                maxmin: true, //开启最大化最小化按钮s
                area: ['800px','500px'],
                content: 'form/addPlan.jsp?id='+project.id+'&sort_number='+row.sort_number
            })
        }
    }
  function view()
  {
      var row = $('#dg').datagrid('getSelected');
        if(row == null)
        {
          layerMsgCustom('必须选择一条数据');
          return;
        }

        layer.open({
            type: 2,
            title: '查看',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px','400px'],
            content: 'form/viewPlan.jsp?id=' + row.id+'&project_id='+ project.id
        })
  }

    function edit() {

        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }

        layer.open({
            type: 2,
            title: '修改',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px','400px'],
            content: 'form/editPlan.jsp?id=' + row.id+'&project_id='+ project.id
        })
    }
    function dele() {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }
        //删除操作属于危险操作，给出提示
        $.messager.confirm('友情提示', '您确定要删除这条数据吗?', function(r) {
            if (r) {
                shuoheUtil.layerTopMaskOn();
                $.ajax({
                    url: "/pm2/plan/deleteMasterPlan.do",
                    type: "POST",
                    dataType: 'json',
                    data: {
                        'id': row.id
                    },
                    error: function() //失败
                    {
                        shuoheUtil.layerTopMaskOff();
                    },
                    success: function(data) //成功
                    {
                        updateSuccess();
                        shuoheUtil.layerTopMaskOff();
                        if(data.result)
                        {
                            shuoheUtil.layerMsgOK(data.describe);
                        }
                        else
                        {
                            shuoheUtil.layerMsgError(data.describe);
                        }
                    }
                });
            }
        });
    }

    function change()
    {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }

        layer.open({
            type: 2,
            title: '变更计划',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px','400px'],
            content: 'form/changePlan.jsp?id=' + row.id+'&project_id='+ project.id
        })
    }


  function updateSuccess()
  {
    $('#dg').datagrid('reload');

  }
  
  
  function functionQuery() {
	    loadDg();
	  }
  function functionClear() {
    $('#equipment_id').textbox('clear');
    $('#equipment_name').textbox('clear');
    $('#use_department').textbox('clear');
    $('#actual_name').textbox('clear');
    loadDg();
  }

    function upMove() {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }
        shuoheUtil.layerTopMaskOn();
        $.ajax({
            url: "/pm2/plan/upMove.do",
            type: "POST",
            dataType: 'json',
            data: {
                'id': row.id
            },
            error: function() //失败
            {
                shuoheUtil.layerTopMaskOff();
            },
            success: function(data) //成功
            {
                updateSuccess();
                shuoheUtil.layerTopMaskOff();
                if(data.result)
                {
                    shuoheUtil.layerMsgOK(data.describe);
                }
                else
                {
                    shuoheUtil.layerMsgError(data.describe);
                }
            }
        });
    }
    function downMove() {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }
        shuoheUtil.layerTopMaskOn();
        $.ajax({
            url: "/pm2/plan/downMove.do",
            type: "POST",
            dataType: 'json',
            data: {
                'id': row.id
            },
            error: function() //失败
            {
                shuoheUtil.layerTopMaskOff();
            },
            success: function(data) //成功
            {
                updateSuccess();
                shuoheUtil.layerTopMaskOff();
                if(data.result)
                {
                    shuoheUtil.layerMsgOK(data.describe);
                }
                else
                {
                    shuoheUtil.layerMsgError(data.describe);
                }
            }
        });
    }


</script>
